import JSONBIG from 'json-bigint';

import _ from 'lodash';
/**
 *
 * @param data
 * @param prop
 */
export function filterTree(data: any[], valKey = 'code'): any[] {
  data.map((item) => {
    item.key = item[valKey];
    item.value = item[valKey];
    item.orgCode = item[valKey];
    item.parentCode = item.orgCode;
    item.storeCode = item.storeCode;
    item.storeName = item.name;
    item.title = item.name;
    if (item.sub) item.children = item.sub;
    delete item.sub;
    delete item.name;
    if (item.children) filterTree(item.children, valKey);
    return data;
  });
  return data;
}

/**
 *
 * @param data ���ں�̨���ص����ݹ��󾫶ȶ�ʧ����
 * @returns
 */
export function transformResponseForBigInt(data) {
  // �� data ��������ת������
  const jsonBig = JSONBIG({
    storeAsString: true,
  });
  return jsonBig.parse(data);
}

export const pickNotNull = (obj: any) => {
  const newObj = { ...obj };
  for (let k: string in newObj) {
    if (newObj[k] == null) {
      delete newObj[k];
    }
  }

  return newObj;
};

export const pickNotEmpety = (obj: any) => {
  const newObj = { ...obj };
  for (let k: string in newObj) {
    console.log(_.isEmpty(newObj[k]));
    if (_.isEmpty(newObj[k])) {
      delete newObj[k];
    }
  }
  console.log(newObj);
  return newObj;
};
